

#include <cegfx/cetransform.h>



ceTransform::ceTransform ()
{
	IQF_CONSTRUCT;
	D3DXMatrixIdentity (&matrix);
}

IQF_IMPLEMENTATION_BEGIN(ceTransform);
IQF_IMPLEMENTATION_END();


void ceTransform::SetIdentity ()
{
	D3DXMatrixIdentity (&matrix);
}

void ceTransform::SetTranslation (float x, float y, float z)
{
	matrix._41 = x;
	matrix._42 = y;
	matrix._43 = z;
}

void ceTransform::SetTranslation (const D3DXVECTOR3& t)
{
	matrix._41 = t.x;
	matrix._42 = t.y;
	matrix._43 = t.z;
}

const D3DXMATRIX& ceTransform::GetMatrix () const
{
	return matrix;
}

D3DXMATRIX& ceTransform::GetMatrix ()
{
	return matrix;
}

void ceTransform::RotateX (float angle)
{
	static D3DXMATRIX mat;
	D3DXMatrixRotationX (&mat, angle);
	D3DXMatrixMultiply (&matrix, &mat, &matrix);
}

void ceTransform::RotateY (float angle)
{
	static D3DXMATRIX mat;
	D3DXMatrixRotationY (&mat, angle);
	D3DXMatrixMultiply (&matrix, &mat, &matrix);
}

void ceTransform::RotateZ (float angle)
{
	static D3DXMATRIX mat;
	D3DXMatrixRotationZ (&mat, angle);
	D3DXMatrixMultiply (&matrix, &mat, &matrix);
}

void ceTransform::Rotate (const D3DXVECTOR3& axis, float angle)
{
	static D3DXMATRIX mat;

	D3DXMatrixRotationAxis (&mat, &axis, angle);
	D3DXMatrixMultiply (&matrix, &mat, &matrix);
}

void ceTransform::RotateGlobalX (float angle)
{
	static D3DXMATRIX mat;
	D3DXMatrixRotationX (&mat, angle);
	D3DXMatrixMultiply (&matrix, &matrix, &mat);
}

void ceTransform::RotateGlobalY (float angle)
{
	static D3DXMATRIX mat;
	D3DXMatrixRotationY (&mat, angle);
	D3DXMatrixMultiply (&matrix, &matrix, &mat);
}

void ceTransform::RotateGlobalZ (float angle)
{
	static D3DXMATRIX mat;
	D3DXMatrixRotationZ (&mat, angle);
	D3DXMatrixMultiply (&matrix, &matrix, &mat);
}

void ceTransform::RotateGlobal (const D3DXVECTOR3& axis, float angle)
{
	static D3DXMATRIX mat;

	D3DXMatrixRotationAxis (&mat, &axis, angle);
	D3DXMatrixMultiply (&matrix, &matrix, &mat);
}


void ceTransform::Translate (float x, float y, float z)
{
	static D3DXMATRIX mat;
	D3DXMatrixTranslation (&mat, x, y, z);

	D3DXMatrixMultiply(&matrix, &mat, &matrix);
}


void ceTransform::TranslateGlobal (float x, float y, float z)
{
	static D3DXMATRIX mat;
	D3DXMatrixTranslation (&mat, x, y, z);

	D3DXMatrixMultiply(&matrix, &matrix, &mat);
}

void ceTransform::Translate (const D3DXVECTOR3& d)
{
	static D3DXMATRIX mat;
	D3DXMatrixTranslation (&mat, d.x, d.y, d.z);

	D3DXMatrixMultiply(&matrix, &mat, &matrix);
}


void ceTransform::TranslateGlobal (const D3DXVECTOR3& d)
{
	static D3DXMATRIX mat;
	D3DXMatrixTranslation (&mat, d.x, d.y, d.z);

	D3DXMatrixMultiply(&matrix, &matrix, &mat);
}

D3DXVECTOR3 ceTransform::GetPosition () const
{
	return D3DXVECTOR3 (matrix._41, matrix._42, matrix._43);
}

